﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using LP580.CG;

public partial class Manage_CG_UserCompanyInfoOperate : System.Web.UI.Page
{
    private string act = Utils.RQ_str("act").ToLower();
    private int id = Utils.RQ_int("id");
    protected void Page_Load(object sender, EventArgs e)
    {
        clsAdmin adm = clsAdmin.getCookieAdmin();
        if (adm == null)
        {
            Utils.WrAlertGo("您尚未成功登陆，请成功登陆后再进行正常操作！", "../Login.aspx");
        }

        if (!this.IsPostBack)
            bindData();
        bindContrl();
    }

    private void bindContrl()
    {
        
    }

    private void bindData()
    {
        if (act == "edit")
        {
            ltMgTitle.Text = "修改管理";
            ltPathTitle.Text = "[修改管理员用户]";
            ltOperTitle.Text = "修改管理员用户";
            clsAdmin cls = new clsAdmin(id);
            tbxAdminName.Text = cls.AdminName;
            tbxAdminPassword.Text = cls.AdminPassword;
            tbxAdminAllowIP.Text = cls.AdminAllowIP;
            cbxLocked.Checked = cls.isLocked;
            btnSave.Text = " 修 改 ";
            tbxAdminName.ReadOnly = true;
        }
        else
        {
            ltMgTitle.Text = "添加管理";
            ltPathTitle.Text = "[添加管理员用户]";
            ltOperTitle.Text = "添加管理员用户";
        }
    }

    protected void btnSave_Click(object sender, EventArgs e)
    {
        string name = tbxAdminName.Text.Trim();
        if (name == "")
        {
            Utils.WrAlertGoBack("帐号名必填不可为空！");
        }
        clsAdmin cls = new clsAdmin(id);
        cls.AdminName = name;
        string pass=tbxAdminPassword.Text;
        if (pass != "")
        {
            cls.AdminPassword = pass;
        }
        cls.isLocked = cbxLocked.Checked;
        cls.AdminAllowIP = tbxAdminAllowIP.Text;
        if (act.ToLower() == "edit")
        {
            clsAdmin.Update(cls);
        }
        else
        {
            if (clsAdmin.ExistAdminName(name))
            {
                Utils.WrAlertGoBack("帐号名已存在不可重复！");
            }
            clsAdmin.Insert(cls);
        }
        Response.Redirect("AdminList.aspx", true);
    }
}